﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Laboration1Uppgift4.View
{
    public class BallView
    {
        // Variabler
        private int _borderSize, _height, _width;
        private SpriteBatch _spriteBatch;
        private Texture2D _backgroundSprite, _ballSprite;
        private Model.BallSimulation _ballSimulation;
        private Camera _camera;


        /// <summary>
        /// Konstruktor 
        /// </summary>
        public BallView(int borderSize, int height, int width, Model.BallSimulation ballSimulation,
                        GraphicsDevice graphicsDevice, ContentManager content, GraphicsDeviceManager graphics)
        { 
            this._borderSize = borderSize; 
            this._height = height;
            this._width = width; 
            this._ballSimulation = ballSimulation;
            this._spriteBatch = new SpriteBatch(graphicsDevice);
            this._backgroundSprite = content.Load<Texture2D>("Textures\\background");
            this._ballSprite = content.Load<Texture2D>("Textures\\basketball");
            this._camera = new Camera(borderSize, graphics.PreferredBackBufferWidth, _ballSimulation.Ball.Radie);

        } 
  
        /// <summary>
        /// Rita ut bakgrund
        /// </summary>
        private void DrawBackground()
        { 
            Rectangle rect = new Rectangle(_borderSize, _borderSize, _width, _height); 
            _spriteBatch.Draw(_backgroundSprite, rect, Color.White); 
        }

        /// <summary>
        /// Rita ut bollen
        /// </summary>
        internal void DrawBallAndScenery()
        {
            _spriteBatch.Begin();

            DrawBackground(); 
            Vector2 convertedCoordinates = _camera.GetCoordinates(_ballSimulation.Ball.BallPosition);
            Rectangle rect = new Rectangle((int)convertedCoordinates.X, (int)convertedCoordinates.Y, _ballSprite.Width, _ballSprite.Height);
            
            _spriteBatch.Draw(_ballSprite, rect, Color.White);
            _spriteBatch.End();
        } 
    }
}
